<?php

class User extends DataObject {
	protected $propertyNames = array("id", "name", "email", "answersGiven", "achievements");
	protected $customProperties = array("answersGiven", "achievements");

	public function __construct(array $propertyNames = NULL) {
		parent::__construct($propertyNames);
		if (!empty($this->id)) {
			$this->answersGiven = BLL::getInstance()->getAnswersGiven($this);
			$this->achievements = BLL::getInstance()->getAchievementsCollected($this);
		}
	}
}

class Question extends DataObject {
	protected $propertyNames = array("id", "questionText", "correctAnswerID", "correctAnswer", "answers");
	protected $indirectProperties = array("correctAnswer" => "PossibleAnswer");
	protected $customProperties = array("answers");

	public function __construct(array $propertyNames = NULL) {
		parent::__construct($propertyNames);
		if (!empty($this->id)) {
			$this->answers = BLL::getInstance()->getAnswersByQuestion($this);
		}
	}
}

class PossibleAnswer extends DataObject {
	protected $propertyNames = array("id", "answerText", "questionID", "question", "sequenceNumber");
	protected $indirectProperties = array("question" => "Question");

	public function isCorrect() {
		return $this->id == $this->question->correctAnswerID;
	}
}

class Achievement extends DataObject {
	protected $propertyNames = array ("id", "description", "explanation");
}
